package leetcode.code1184;

import leetcode.IDebug;
import leetcode.helper.H;

public class Solution implements IDebug {

	public int distanceBetweenBusStops(int[] distance, int start, int destination) {
		int sum1 = 0, sum2 = 0;// 区间内，区间外距离和
		int a = Math.min(start, destination), b = Math.max(start, destination);// 从左到右的起始位置和结束位置
		for (int i = 0; i < distance.length; i++) {
			if (i >= a && i < b) {
				sum1 += distance[i];
			} else {
				sum2 += distance[i];
			}
		}
		return Math.min(sum1, sum2);
	}

	@Override
	public void debug4() {
		H.compare(1, this.distanceBetweenBusStops(H.str2array3("[1,2,3,4]"), 0, 1));
		H.compare(3, this.distanceBetweenBusStops(H.str2array3("[1,2,3,4]"), 0, 2));
		H.compare(4, this.distanceBetweenBusStops(H.str2array3("[1,2,3,4]"), 0, 3));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
